package logic

import (
	"context"
	"fmt"
	"go-zero-demo/mall/user/rpc/internal/svc"
	"go-zero-demo/mall/user/rpc/model"
	"go-zero-demo/mall/user/rpc/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// rpc getUser(UserRequest) returns(UserResponse);
func (l *RegisterLogic) Register(in *user.RegisterReq) (*user.RegisterResp, error) {
	//_, err := l.svcCtx.StudentModel.FindOne(l.ctx, in.Id)
	//if err != nil {
	//	fmt.Println("xxxxxxxxxxx")
	//	return nil, err
	//}

	_, err := l.svcCtx.StudentModel.Insert(l.ctx, &model.Student{
		Sno:       in.Id,
		Sname:     "嘻嘻嘻",
		Password1: in.Password,
		Login:     in.Id,
	})

	if err != nil {
		fmt.Println("111111111")
		return nil, err
	}
	return &user.RegisterResp{
		Msg: "注册成功",
	}, nil
}
